# from nester_czx import print_lol
import pickle
man= []
other = []
try:
    data=open('sketch.txt')
    for each_line in data:
        try:
            (role, line_spoken) = each_line.split(':', 1)
            line_spoken = line_spoken.strip() # 去除空格
            if(role == 'Man') :
                man.append(line_spoken)
            elif role=='Other Man':
                other.append(line_spoken)
        except ValueError:
            pass
    data.close()
except IOError:
    print('The datafile is missing')
try:
    # open() 可以设置访问模式, w表示写
    with open('man_data.txt','wb') as man_file:
        pickle.dump(man, man_file)
    # print() 可以把数据写至磁盘
        # print_lol(man, fn=man_file)
    with open('other_data.txt','wb') as other_file:
         pickle.dump(other, other_file)
        # print_lol(other, fn= other_file)
except IOError as err:
    print('File Error',str(err))
except pickle.PickleError as perr:
    print('File Error',str(perr))


